<?php

$server = new swoole_server('0.0.0.0',3333);

$server->set([
    'worker_num'=>2,
    'task_worker_num'=>3
]);

$server->on('receive',function(\Swoole\Server $serv,$fd,$reactor_id,$data){
//    $serv->task('task data');
    //$serv->task('task data',-1,function($serv,$task_id,$data){
    //	echo 'task finish'.$data;
    //});
//    $res = $serv->taskwait('wait data',3);
    $res = $serv->taskWaitMulti([1,2,3],-1);//超时返回错误结果，然后继续向下执行
//    $res = $serv->taskCo([1,2,3],5);//超时不返回错误结果，然后继续向下执行
    var_dump($res);
    echo 'login....'.PHP_EOL;

    var_dump($serv->stats());
});

$server->on('task',function($serv,$task_id,$src_worker,$data){
    sleep(3);
    echo 'task...'.$data.PHP_EOL;
    return 'success'.$data;
    //$serv->finish('success');
});

$server->on('finish',function($serv,$task_id,$data){
    echo 'finish...'.$data.PHP_EOL;
});

$server->start();
